What is @turf/line-offset?
@turf/line-offset is a module in the Turf.js library that allows you to create parallel lines at a specified distance from the input line. This can be useful for various geospatial operations such as creating buffer zones, road networks, or any application where you need to generate offset lines from a given line geometry.
What are @turf/line-offset's main functionalities?
Create an offset line
This feature allows you to create a line that is offset by a specified distance from the original line. In this example, the line is offset by 2 miles.
const turf = require('@turf/turf');
const line = turf.lineString([[0, 0], [10, 10]]);
const offsetLine = turf.lineOffset(line, 2, { units: 'miles' });
console.log(JSON.stringify(offsetLine));
Other packages similar to @turf/line-offset
jsts
JSTS (JavaScript Topology Suite) is a JavaScript library of spatial predicates and functions for processing geometry. It provides similar functionality to @turf/line-offset, such as creating buffer zones and offset lines, but it is more comprehensive and includes a wider range of geometric operations.
geolib
Geolib is a library to provide basic geospatial operations like distance calculation, bounding boxes, and more. While it does not specifically focus on line offsetting, it offers a variety of geospatial utilities that can complement the functionalities provided by @turf/line-offset.
@turf/line-offset
lineOffset
Takes a line and returns a line at offset by the specified distance.
Parameters
-
geojson
(Geometry | Feature<(LineString | MultiLineString)>) input GeoJSON
-
distance
number distance to offset the line (can be of negative value)
-
options
Object Optional parameters (optional, default {}
)
options.units
string can be degrees, radians, miles, kilometers, inches, yards, meters (optional, default 'kilometers'
)
Examples
var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]], { "stroke": "#F00" });
var offsetLine = turf.lineOffset(line, 2, {units: 'miles'});
var addToMap = [offsetLine, line]
offsetLine.properties.stroke = "#00F"
Returns Feature<(LineString | MultiLineString)> Line offset from the input line
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Installation
Install this single module individually:
$ npm install @turf/line-offset
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf